package com.chiffoyqc.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chiffoyqc.config.URLConfig;
import com.chiffoyqc.factory.ReturnCodeFactory;
import com.chiffoyqc.model.BillingData_Rep;
import com.chiffoyqc.model.MeterData_Rep;
import com.chiffoyqc.service.Interface.IHandleBillingData;
import com.chiffoyqc.utils.HttpHelper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/7/18.
 * 7.11. 获取抄表结算数据
 */
@Service
public class BillingDataService implements IHandleBillingData {
    @Override
    public Map<String, Object> handleRequestMessage(String postData) {
        System.out.println("获取抄表结算数据 传给zsy参数：" + postData);
        String result = HttpHelper.sendPostForNormal(URLConfig.billingData, postData, "utf-8");
        System.out.println("获取抄表结算数据 zsy返回的结果："+ result);
        if(!result.equals("") ){
//            Map<String,Object> dataMap = new HashMap<>();
            JSONObject jsonObject = JSON.parseObject(result);
            JSONArray paramArray = jsonObject.getJSONArray("param");
            jsonObject.put("param",JSON.toJSONString(paramArray));
//            /**组织returnCode returnMsg*/
//            dataMap = ReturnCodeFactory.createReturnCodeMap(dataMap,jsonObject);

//            /**组织其他数据*/
//            JSONArray paramsArray = jsonObject.getJSONArray("param");
//            if(paramsArray != null && paramsArray.size() != 0){
////                BillingData_Rep billingData_rep;
////                List<BillingData_Rep> list = new LinkedList<>();
////                for(int i = 0 ,len = paramsArray.size(); i < len ; i++){
////                    billingData_rep = paramsArray.getObject(i, BillingData_Rep.class);
////                    list.add(billingData_rep);
////                }
//
//                dataMap.put("param",paramsArray);
//            }



            return jsonObject;
        }


        return null;
    }
}
